package com.permissions.dispatcher.processor.impl;

import com.permissions.dispatcher.processor.util.Helpers;
import com.squareup.javapoet.MethodSpec;

import javax.lang.model.type.TypeMirror;

/**
 * 生成java方法ability核心类
 */
public class AbilityProcessorUnit extends JavaBaseProcessorUnit {
    @Override
    void addRequestPermissionsStatement(
            MethodSpec.Builder builder, String targetParam, String permissionField, String requestCodeField) {
        builder.addStatement("$N.requestPermissionsFromUser($N, $N)", targetParam, permissionField, requestCodeField);
    }

    @Override
    void addShouldShowRequestPermissionRationaleCondition(
            MethodSpec.Builder builder, String targetParam, String permissionField, boolean isPositiveCondition) {
        builder.beginControlFlow(
                "if ($N$T.shouldShowRequestPermissionRationale($N, $N))",
                isPositiveCondition ? "" : "!",
                permissionUtils,
                targetParam,
                permissionField);
    }

    @Override
    String getActivityName(String targetParam) {
        return targetParam;
    }

    @Override
    public TypeMirror getTargetType() {
        return Helpers.typeMirrorOf("ohos.aafwk.ability.Ability");
    }
}
